<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close"
    :append-to-body="true">
    <el-form ref="form" :model="form" :rules="rules" label-width="0.8rem">
      <el-form-item label="类型名称" prop="leixingmc">
        <el-input v-model.trim="form.leixingmc" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="类型编码" prop="leixingbm">
        <el-input v-model.trim="form.leixingbm" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="排序">
        <el-input v-model.trim="form.paixu" autocomplete="off" min="1" type="number" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addguajialx, updateguajialx } from '@/api/cangkujichu'
export default {
  name: 'UserManagementEdit',
  data() {
    return {
      form: {
        leixingmc: '',
        leixingbm: '',
        paixu: ''
      },
      rules: {
        leixingmc: [
          { required: true, trigger: 'blur', message: '请输入名称' },
        ],
      },
      title: '',
      dialogFormVisible: false,
    }
  },
  created() { },
  mounted() {
  },
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '新增'
        this.editHw = false
      } else {
        this.title = '编辑'
        this.form = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          if (this.title == '编辑') {
            const { msg } = await updateguajialx(this.form)
          } else {
            const { msg } = await addguajialx(this.form)
          }
          this.$baseMessage('操作成功', 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.el-select {
  width: 100%;
}
</style>
